package main

import "fmt"

type Person struct {
	Name string
}

type Dog struct {
	Name string
}

// 给A类型绑定一个方法
func (person Person) test() {
	person.Name = "jackie"
	fmt.Println("test() =》", person.Name)
}

func (person Person) speak() {
	fmt.Println(person.Name, "是一个好人")
}

func (person Person) calSum() {
	sum := 0
	for i := 1; i <= 1000; i++ {
		sum += i
	}
	fmt.Println("结果是", sum)
}

func (person Person) calSum2(n int) {
	sum := 0
	for i := 1; i <= n; i++ {
		sum += i
	}
	fmt.Println("结果是", sum)
}

func (person Person) calSum3(n1, n2 int) (sum int) {
	return n1 + n2
}

func main() {
	var p Person
	p.Name = "tom"
	p.test() //调用方法
	// fmt.Println("main() p.Name=", p.Name) //输出tom 值传递

	// var dog Dog
	// dog.Name = "小白"
	// dog.test()

	//调用
	p.speak()
	p.calSum()
	p.calSum2(10)
	//计算a+b并返回
	n1 := 10
	n2 := 20
	sum := p.calSum3(n1, n2)
	fmt.Println("sum =", sum)
}
